package company.shopee_F;

import java.util.Scanner;

public class Shopee06 {

    private static int m, n, result = 0;
    private static int[][] array;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String mn = sc.nextLine();
        String[] strs = mn.split(",");
        m = Integer.parseInt(strs[0]);
        n = Integer.parseInt(strs[1]);

        array = new int[m][n];
        for (int i = 0; i < m; i++) {
            String[] tmp = sc.nextLine().split(",");
            for (int j = 0; j < n; j++) {
                array[i][j] = Integer.parseInt(tmp[j]);
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                helper(i, j, 1);
            }
        }
        System.out.println(result);
    }

    private static void helper(int x, int y, int step) {
        //向左
        int num = array[x][y];
        boolean isMove = false;
        if (x - 1 >= 0 && array[x - 1][y] > num) {
            helper(x - 1, y, step + 1);
            isMove = true;
        }
        //向右
        if (x + 1 < n && array[x + 1][y] > num) {
            helper(x + 1, y, step + 1);
            isMove = true;
        }
        //向上
        if (y - 1 >= 0 && array[x][y - 1] > num) {
            helper(x, y - 1, step + 1);
            isMove = true;
        }
        //向下
        if (y + 1 < m && array[x][y + 1] > num) {
            helper(x, y + 1, step + 1);
            isMove = true;
        }
        if (!isMove) {
            result = Math.max(step, result);
        }
    }
}
